<CFSET sdate = CreateODBCDate(url.from)>
<CFSET tdate = CreateODBCDate(url.to)>
<CFSET ROWCOUNTER=1>
<CFSET dayStr = "SUN,MON,TUE,WED,THU,FRI,SAT">
<cfset wsid = url.vw>

<cfscript>
	if ( uCase(client.DBMS) eq 'MSSQL')
		concat = '(PA.LASTNAME+, +PA.FIRSTNAME+" "+PA.MIDDLENAME)';
	else
		concat = 'concat(PA.LASTNAME,", ",PA.FIRSTNAME," ",PA.MIDDLENAME)';
</cfscript>

<CFQUERY NAME="getPowerUser" DATASOURCE="#client.company_dsn#">
    SELECT Count(PERSONNELIDNO) AS COUNT
    FROM CINWSPOWERUSER 
    WHERE PERSONNELIDNO ='#client.chapa#'
</CFQUERY>

<cfquery name="formDtls" datasource="#client.company_dsn#" maxrows="1">
	SELECT APPROVED FROM CINWSFILE WHERE DOCNUMBER ='#wsid#'
</cfquery>
<cfset isPosted = FALSE>
<cfif Len(formDtls.APPROVED)>
	<cfif formDtls.APPROVED eq 'Y'>
    	<cfset isPosted = TRUE>
    </cfif>
</cfif>

<cfquery name="getPerson" datasource="#client.company_dsn#">
	<cfif uCase(client.DBMS) eq 'MSSQL'>
     SELECT (PA.LASTNAME+', '+PA.FIRSTNAME+' '+PA.MIDDLENAME )AS NAME, 
    <cfelse>
      SELECT  concat(PA.LASTNAME,", ",PA.FIRSTNAME," ",PA.MIDDLENAME) AS NAME, 
    </cfif>
    
	WSP.PERSONNELIDNO, PA.GUID
    FROM CINWSFILEPERSON WSP
    LEFT JOIN CMFPA PA ON PA.PERSONNELIDNO = WSP.PERSONNELIDNO
    WHERE WSFILENO = '#wsid#'
</cfquery>
<cfset Request.getPerson = getPerson>
<cfset col = DateDiff("d",sdate,tdate) + 3>  

<table width="100%" align="center" style="margin-left:2" class="dailyTable">
	<TR>
    	<TH width="3%">&nbsp;</TH>
        <TH width="20%" colspan="2">EMPLOYEE NAME</TH>
        <TH width="7%">DUTY</TH>
    	<cfloop condition= "#sdate# LTE #tdate#">
			<TH width="10%">
				<cfoutput>
                	<b>#DateFormat(sdate,"DD-MMM")#<BR />
            		#ListGetAt(dayStr,DayOfWeek(sdate))#</b>
				</cfoutput>
            </TH>
    	<CFSET sdate= DateAdd("d",1,sdate)>    
    	</cfloop>    
    </TR>

    <cfoutput query="getPerson">
    <cfquery name="getPosition" datasource="#client.company_dsn#">
    	SELECT POS.DESCRIPTION
        FROM CMFPA PA

        LEFT JOIN CLKPOSITION POS ON POS.POSITIONCODE = PA.POSITIONCODE
        WHERE PA.PERSONNELIDNO = '#PERSONNELIDNO#'
        
    </cfquery>

    <cfset Request.id = PERSONNELIDNO>
    <cfset Request.wsid = wsid>
    <TR BGCOLOR = "#IIF(CURRENTROW MOD 2, "CLIENT.COLOR_TBLSET2", "CLIENT.COLOR_TBLSET1")#" class="row">
    	<TD>#CurrentRow#</TD>
        <TD>#NAME#</TD>
        <TD>&nbsp;-&nbsp;#getPosition.DESCRIPTION#</TD> 
        <TD>SCHEDULE</TD>
        <CFSET sdate = CreateODBCDate(url.from)>
    	<cfloop condition= "#sdate# LTE #tdate#">
        	
        	<cfset jdate = DateFormat(sdate,"DDYYYYMM")>
            <cfset concat = jdate&CurrentRow&PERSONNELIDNO>
        	<cfset Request.rdate = sdate>
        	<cfmodule template="leaveDtls.cfm">    
            <cfmodule template="_getSched.cfm" sdate="#sdate#">    
            <cfset isLv = false> 
            <cfif ucase(STATUS) neq ''>
            	<cfset isLv = true> 
            	<cfif ucase(STATUS) eq 'Y'>
                    <cfset style="color:##00C !important;text-align:center; cursor:pointer">
                     <cfset msg = sdesc&": Click to change schedule.">
                <cfelse>
                	 <cfset style="color:##F60;text-align:center; cursor:pointer">
                     <cfset msg = sdesc&": Click to change schedule.">
                </cfif>
                
               <cfif not Len(skedQry.DAYTYPE)>
               		<cfset skedQryDesc = "-none-">
               <cfelse>
               		<cfset skedQryDesc = skedQry.DESCRIPTION>
               </cfif> 
			   <cfif getPowerUser.Count and NOT isPosted>
                   <cfset cont = "#skedQryDesc#<BR/><span style='#style#; text-decoration:none;'><li><b>#LVTYPE#</li></span>">
                   <cfinclude template="_enableEdit.cfm">
               <cfelse>
                  <TD style="#style#"  title="#sdesc#">
                      <em>#skedQry.DESCRIPTION#</em>
                      <li><b>#LVTYPE#</b></li>
                  </TD>
               </cfif>    
            <cfelse>
                    <cfif ucase(skedQry.DAYTYPE) neq 'RD'>
                    	<cfset style="color:##000; text-align:left">
                        <cfset msg = "Click to change schedule">
                        <cfif Len(skedQry.DAYTYPE)>
                        	<cfset cont = skedQry.DESCRIPTION>
                        <cfelse>
                        	<cfset cont = "-none-">
                        </cfif>
                    <cfelse>
                    	<cfset style="color:##F00; text-align:center">
                        <cfset msg = "Day-Off: Click to change schedule">
                       	<cfif Len(skedQry.DAYTYPE)>
                        	<cfset cont = '<b><span style="#style#">#skedQry.DAYTYPE#</span></b>'>
                        <cfelse>
                        	<cfset cont = '<b><span style="#style#">-none-</span></b>'>
                        </cfif>
                    </cfif>
                    
                    <cfif getPowerUser.Count and NOT isPosted>
                       <cfinclude template="_enableEdit.cfm">
                    <cfelse>
                    	<td style="#style#"><em>#cont#</em></td>
                    </cfif>
				
            </cfif>
			<CFSET sdate= DateAdd("d",1,sdate)>     
           
        </cfloop>	
    </TR>
    </cfoutput>
     <cfoutput>  
    <TD COLSPAN = 3 style="color:black; width:100%; background:inherit; height:18">  
      &nbsp;Headcount:&nbsp;#getPerson.RECORDCOUNT#
    </TD> 
     </cfoutput>
</table>
 




